package com.yami.shop.service.impl;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.PhoneUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.dto.ShopAuditingInfoDto;
import com.yami.shop.bean.model.ShopAuditing;
import com.yami.shop.bean.param.AuditingInfoParam;
import com.yami.shop.dao.ShopAuditingMapper;
import com.yami.shop.service.ShopAuditingService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 商家审核信息
 *
 * @author Dwl
 * @date 2019-09-19 14:02:57
 */
@Service
@RequiredArgsConstructor
public class ShopAuditingServiceImpl extends ServiceImpl<ShopAuditingMapper, ShopAuditing> implements ShopAuditingService {

    @Value("${yami.expose.operation.auth:}")
    private Boolean permission;

    private final ShopAuditingMapper shopAuditingMapper;


    @Override
   public  ShopAuditing getShopAuditingByUserId(String userId){
        return shopAuditingMapper.getShopAuditingByUserId(userId);
    }

    @Override
    public IPage<ShopAuditingInfoDto> auditingInfoList(Page<ShopAuditingInfoDto> page, AuditingInfoParam auditingInfoParam) {
        IPage<ShopAuditingInfoDto> auditingPage = shopAuditingMapper.auditingInfoList(page, auditingInfoParam);
        if (BooleanUtil.isFalse(permission)) {
            for (ShopAuditingInfoDto auditingInfoDto : auditingPage.getRecords()) {
                auditingInfoDto.setMobile(PhoneUtil.hideBetween(auditingInfoDto.getMobile()).toString());
            }
        }
        return auditingPage;
    }

}
